<?PHP
date_default_timezone_set("Asia/Chongqing");
include("../config/connect.php");
include("../public/common.php");

$id = CheckUrlParamNoDie("id");
$nPage = CheckUrlParamNoDie("page");

if($nPage == "")
	$nPage = 0;
	
if($id == "")
{
	echo "error";
	exit;
}

// Normal
$stime = date('Ymd', strtotime("-3 day"));
$sql = "from duoduo_mall_order where (handle_code=0 or handle_code=1) and u_id='$id' and (fxje<>0 or date(order_time)>'$stime')";

$count = mysql_num_rows(mysql_query("select id ".$sql));

$PAGE_SIZE = 6;
$limit = " limit ". $nPage*$PAGE_SIZE .",$PAGE_SIZE";
$sql = "select * ".$sql." order by order_time desc".$limit;
$result = mysql_query( $sql );

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	font-size: 12px;
	color: #000;
	font-family: 宋体;
}
</style>
</head>

<body style="margin-left:0; margin-top:0; margin-right:0; margin-bottom:0">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
      <tr bgcolor="#F4D662">
        <td width="151" height="24" align="center"><strong>序号</strong></td>
        <td width="244" align="center"><strong>商城标识</strong></td>
        <td width="244" align="center"><strong>下单日期</strong></td>
        <td width="197" align="center"><strong>订单号</strong></td>
        <td width="205" align="center"><strong>返现额</strong></td>
        <td width="368" align="center"><strong>状态</strong></td>
      </tr>
      <?PHP 
	  $i = $PAGE_SIZE * $nPage + 1;
	  if ($count > 0){
	  while( $result && $row = mysql_fetch_assoc( $result )) {
	  ?>
      <tr bgcolor="<?PHP if ($i % 2 == 0) echo "#EAE7BB"; else echo "#EEEEEE" ?>">
        <td height="24" align="center"><?PHP echo $i; ?></td>
        <td align="center"><?PHP echo $row["merchant_id"]; ?></td>
        <td align="center"><?PHP echo $row["order_time"]; ?></td>
        <td align="center"><?PHP echo substr($row["order_code"], 0, 8)."**".substr($row["order_code"], 10, 4); ?></td>
        <td align="center"><?PHP echo "￥".round($row["commission"] * 0.6, 2); ?></td>
        <td align="left">&nbsp;&nbsp;&nbsp;&nbsp;<?PHP if ($row["tiqian"] == 1) echo "<img src='images/accept.gif'>&nbsp;已申请提前返现，处理中"; else if ($row["handle_code"] == 0 && $row["stat_desc"] == "未核对") echo "<img src='images/clock.gif'>&nbsp;待确认"; else echo "<img src='images/accept.gif'>&nbsp;正在处理中"; ?>&nbsp;&nbsp;
        <?PHP if($row["handle_code"] == 0 && $row["stat_desc"] == "未核对" && $row["fxje"] > 0 && $row["tiqian"] == 0) echo '<a href="javascript:void(0)" onclick="OnShenqingFX('.$row["id"].')">申请提前返现</a>'; ?>
		</td>
      </tr>
      <?PHP
	  $i++;
		}
		}
		else
		{
			echo "<tr><td align='center'>暂时没有数据</td></tr>";
		}
		?>
</table>
<div>
<table width="100%" cellspacing="4">
  <tr>
<td width="560">&nbsp;如果您刚下单，请耐心等待30分钟就能显示待确认订单。返现到账日期视商城而定，一般是1~3个月&nbsp;</td>
<td id="refresh">&nbsp;您也可以：<a href="javascript:void(0)" onclick="OnGetMallOrder()">立即获取订单</a></td>

<td align="right">
<?PHP if ($count > $PAGE_SIZE) {?>
<a href="?page=0&id=<?PHP echo $id; ?>">首页</a>&nbsp;&nbsp;
<?PHP if ($nPage > 0) {?>
<a href="?page=<?PHP echo $nPage-1; ?>&id=<?PHP echo $id; ?>">上一页</a>&nbsp;&nbsp;
<?PHP } ?>
<?PHP if ($nPage < intval($count / $PAGE_SIZE)) {?>
<a href="?page=<?PHP echo $nPage+1; ?>&id=<?PHP echo $id; ?>">下一页</a>&nbsp;&nbsp;
<?PHP } ?>
<a href="?page=<?PHP echo intval($count / $PAGE_SIZE); ?>&id=<?PHP echo $id; ?>">尾页</a>&nbsp;
<?PHP } ?></td>

</tr>
</table>

</div>

</body>
</html>

<script language="javascript" src="../js/jquery.min.js"></script>
<script language="javascript">
function OnGetMallOrder()
{
	document.getElementById("refresh").innerHTML = "<img src=\"images/loading.gif\" align=\"absmiddle\" />&nbsp;获取订单中，请稍后...&nbsp;";
	var url = "http://www.gouwutu.com/new/mall/admin/api_mallgetorders.php?userid=<?PHP echo $id ?>";
	$.ajax({	url: url,
			async: true,
			success:function(res)
			{
//				alert(res);
				document.getElementById("refresh").innerHTML = "&nbsp;您也可以：<a href=\"javascript:void(0)\" onclick=\"OnGetMallOrder()\">立即获取订单</a>";
				if (res != "")
					self.opener.location.reload();	
           }
	})
}

var mallorderid=0;
function OnShenqingFX(orderid)
{
	mallorderid=orderid;
	var url = "http://www.gouwutu.com/new/mall/admin/api_shenqing_fx.php?userid=<?PHP echo $id ?>&id="+orderid;
	$.ajax({	url: url,
			async: true,
			success:function(res)
			{
				var obj = eval("("+res+")");
				if (obj.code==2)
				{
					if (obj.less_fx_tubi >= 0)
					{
						var ret = confirm("您准备提前申请本次 " + obj.want_fx / 100 + " 元返现，将冻结 " + obj.want_fx + " 个兔币，您确定要提前申请吗？");
						if (ret)
							setTimeout("ConfirmFX(mallorderid)",10);
					}
					else
					{
						alert("您还差 " + Math.abs(obj.less_fx_tubi) + " 个兔币才能申请提前返现哦。欲赢取更多兔币，请参见相关说明。");
					}
				}
           }
	})
}
function ConfirmFX(orderid)
{
	var url = "http://www.gouwutu.com/new/mall/admin/api_shenqing_fx.php?confirm=1&userid=<?PHP echo $id ?>&id="+orderid;
	$.ajax({	url: url,
			async: true,
			success:function(res)
			{
				var obj = eval("("+res+")");
				if (obj.code==1)
				{
					alert("恭喜您申请成功，24小时内就能收到返现金额，请留意手机短信通知。");
					window.location.reload();
				}
				else
					alert("申请失败，请重试看看。");
           }
	})
}

</script>